<?php
include 'controller_sql.php';

$Database = init_connect_db();
$htmlModifPopup = '';

function setUpModificationPopUp($id)
{
	$lastName = '';
	$firstName = '';
	$mail = '';
	$dob = '';
	$urlPath = '';
	
	$result = get_info_from_user($id);
	foreach ($result as $key => $value)
	{
		if ($key == 'lastName')
			$lastName = $value;
		else if ($key == 'firstName')
			$firstName = $value;
		else if ($key == 'email')
			$mail = $value;
		else if ($key == 'dateOfBirth')
			$dob = $value;
		else if ($key == 'imageUrl')
			$urlPath = $value;
	}
	$Array = explode(' ', $dob);
	$dob = $Array[0];
	
	if ($urlPath == NULL || $urlPath == "")
		$urlPath = 'http://fakeimg.pl/160x180/';
	
	$htmlModifPopup = '<div class="row-fluid">
              <div class="span6 bgcolor">
                <label for="firstName">First Name</label>
                <input type="text" id="firstName" placeholder="Peter" value="'.$firstName.'">
              </div>
              <div class="span6 bgcolor" >
                <label for="lastname">Last Name</label>
                <input type="text" id="lastname" placeholder="Jones" value="'.$lastName.'">
              </div>
            </div>

            <div class="row-fluid topPadding10">
              <div class="span6 bgcolor" >
                <label for="email">E-mail</label>
                <input type="text" id="email" placeholder="Type something" value="'.$mail.'">
              </div>

              <div class="span6 bgcolor" >
                <label for="dateofbirth">Date of birth</label>
                <input type="text" id="dateofbirth" placeholder="mm/dd/YYYY" value="'.$dob.'">
              </div>
            </div>

            <div class="row-fluid topPadding10">

              <div class="span6 bgcolor">
                <label for="password">Password</label>
                <input type="password" id="password" placeholder="Type something">
              </div>

              <div class="span6 bgcolor" >
              <label for="confirmpassword">Confirmation password</label>
              <input type="password" id="confirmpassword" placeholder="Type something" >
            </div>
          </div>
        </div>

        <fieldset class="topPadding10">
          <legend>Photo</legend>
          <div class="row-fluid">
            <div class="span6 bgcolor">
             <div>
              <img id="pictureProfil" src="'.$urlPath.'" alt="previewuser" class="leftAnchor">
            </div>
          </div>
          <div class="span6 bgcolor">
            <div class="browse centerVertically">
              <label id="labelUploadUser" for="imageUserPreview">Upload</label>
              <input type="file" name="image" id="imageUserPreview" class="input_text"/>
              <button class="btn btn-success"><i class="icon-plus-sign icon-white"></i> Upload</button>
            </div>
          </div>

        </div>
        <div class="row-fluid bgcolor topPadding20">
        <button class="btn btn-success btn-large centerButtonPopup" onclick="submitModificationUser();">Submit</button>
        </div>
      </fieldset>';
	  
	  return $htmlModifPopup;
}

function setUpUserInformation($id)
{
	$lastName = '';
	$firstName = '';
	$mail = '';
	$dob = '';
	$urlPath = '';
	
	$result = get_info_from_user($id);
	foreach ($result as $key => $value)
	{
		if ($key == 'lastName')
			$lastName = $value;
		else if ($key == 'firstName')
			$firstName = $value;
		else if ($key == 'email')
			$mail = $value;
		else if ($key == 'dateOfBirth')
			$dob = $value;
		else if ($key == 'imageUrl')
			$urlPath = $value;
	}
	$Array = explode(' ', $dob);
	$dob = $Array[0];
	//setUpModificationPopUp($lastName, $firstName, $mail, $dob, $urlPath);
	
	$UserInfo = '<small>'.$lastName.
				'<br>'.$firstName.
				'<br>'.$mail.
				'<br>'.$dob.'<br></small>';
	if ($urlPath != '' && $urlPath != 'NULL')
		$UrlUserPicture = $urlPath;
	else
		$UrlUserPicture = 'http://fakeimg.pl/160x180/';
	
	$header_user = '<div class="row-fluid">
			<div class="span2">
			  <img src='.$UrlUserPicture.' alt="user picture">
		  </div>
		  
		  <div class="span3">
			<p class="lead">'.$UserInfo.'
			  <a href="" data-width="500" data-rel="popup1" class="poplight btn btn-primary btn-medium">Modify</a>
			</p>
		  </div>';
	return $header_user;
}

function setUpPostedArticlesFromUser($id)
{
	$Rows = '';

	$result = get_title_places_by_user_id($id);

	while($place = mysql_fetch_array( $result ))
	{
	    $idPlace = $place['id'];
		$Rows = $Rows.'<tr>
            <td><a>'.$place['title'].'</a></td>
            <td>'.$place['dateEdit'].'</td>
            <td>
              <a onClick="deleteArticle('.$idPlace.');"><img height="16" width="16" src="../img/delete.png" alt="delete icon"/></a>
			  <a href="#addNewPlace" role="button" class="leftPadding10" data-toggle="modal"><img height="16" width="16" src="../img/modify_icon.png" alt="modify icon"/></a>		  </td>
          </tr>
		  ';
	}
	return $Rows;
}

function setUpPostedCommentFromUser($id)
{
	$Comments = '';
	$result = get_title_comments_by_user_id($id);
	
	while($comment = mysql_fetch_array($result))
	{
		$idComment = $comment['id'];
		$Comments = $Comments.'<tr>
				<td><a>'.$comment['title'].'</a></td>
              <td><a>'.$comment[1].'</a></td>
              <td>'.$comment['dateEdit'].'</td>
              <td>
                <a onClick="deleteComment('.$idComment.');" alt="Delete"><img height="16" width="16" src="../img/delete.png"/></a>
              </td>
            </tr>';
	}
	return $Comments;
}

function createSubmitButton($id)
{
  return ('<button type="submit" onClick="submitNewArticle('.$id.');" class="btn btn-success btn-large topPadding20">Submit</button>');
}

function getIDConnectedUser()
{
	if (isset($_SESSION['id']))
	{}
	$id = $_SESSION['id'];

	return $id;
}

?>